225A - Dice Tower - CodeForces Solution


constructive algorithms greedy *1100

Please click on ads to support us..

Python Code:

'''Author : seraph14'''
import sys, io, os
import heapq
if 'PyPy' in sys.version:
    from _continuation import continulet
else:
    import threading
input = sys.stdin.readline

hqp = heapq.heappop
hqs = heapq.heappush

def _print(*argv, sep=" "):
    sys.stdout.write(sep.join(map(str, argv)) + "\n")

def inp():
    return (int(input()))

def inlt():
    return (list(map(int, input().split())))

def insr():
    if input == sys.stdin.readline:
        s = input()
        return list(s.strip())
    else:
        s = input().decode()
        return (list(s[:len(s)-2]))

def invr():
    return (map(int, input().split()))

def get_bool(right):
    return "YES" if right else "NO"

def solve():
    pass

def main():
    n = inp()
    can = True
    x = inp()
    candidates = set(range(1, 7))
    candidates.discard(7-x)

    for _ in range(n):
        a, b = invr()
        if not can:
            continue
        for c in [a, b, 7-a, 7-b]:
            candidates.discard(c)
        can &= len(candidates) == 1
        top = candidates.pop() if candidates else x
        candidates = set(range(1, 7))
        candidates.discard(7-top)
    
    _print(get_bool(can))


if __name__ == '__main__':
    if 'PyPy' in sys.version:

        def bootstrap(cont):
            call, arg = cont.switch()
            while True:
                call, arg = cont.switch(
                    to=continulet(lambda _, f, args: f(*args), call, arg))
        cont = continulet(bootstrap)
        cont.switch()
        main()
    else:
        sys.setrecursionlimit(1 << 30)
        threading.stack_size(1 << 27)

        main_thread = threading.Thread(target=main)
        main_thread.start()
        main_thread.join()

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int check[7]{};
int main()
{
    int n,x,a,b,sum=0;
    cin>>n>>x;
    for(int i=0 ; i<n ; i++)
    {
        cin>>a>>b;
        check[a]=1;
        check[7-a]=1;
        check[b]=1;
        check[7-b]=1;
    }
    for(int i=0 ; i<=6 ; i++)
        sum+=check[i];
    if(sum==4)
        cout<<"YES";
    else
        cout<<"NO";
}


Comments

Submit
0 Comments
More Questions

461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal
589. N-ary Tree Preorder Traversal
1299. Replace Elements with Greatest Element on Right Side
1768. Merge Strings Alternately
561. Array Partition I
1374. Generate a String With Characters That Have Odd Counts
1822. Sign of the Product of an Array
1464. Maximum Product of Two Elements in an Array
1323. Maximum 69 Number
832. Flipping an Image
1295. Find Numbers with Even Number of Digits
1704. Determine if String Halves Are Alike
1732. Find the Highest Altitude
709. To Lower Case
1688. Count of Matches in Tournament
1684. Count the Number of Consistent Strings
1588. Sum of All Odd Length Subarrays
1662. Check If Two String Arrays are Equivalent
1832. Check if the Sentence Is Pangram
1678. Goal Parser Interpretation
1389. Create Target Array in the Given Order
1313. Decompress Run-Length Encoded List